package com.colin.app.activity.other.pay;

import android.support.annotation.IdRes;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.colin.app.R;
import com.colin.app.app.AppActivity;
import com.colin.app.pay.PayUtil;
import com.colin.app.pay.callback.IPayListener;

/**
 * https://docs.open.alipay.com/204/105296/ 支付宝
 */
public class PayActivity extends AppActivity implements View.OnClickListener {
    private TextView text_pay_tips;
    private TextView text_pay_price;
    private RadioGroup radio_pay_choose;
    private final static int PAY_DEFALUT = -1;
    private int pay_way = PayUtil.PAY_WX;

    @Override
    public void initPresenter() {

    }

    @Override
    public int initViewLayoutID() {
        return R.layout.activity_pay;
    }

    @Override
    public void initView() {
        this.text_pay_tips = (TextView) this.findViewById(R.id.text_pay_tips);
        this.text_pay_price = (TextView) this.findViewById(R.id.text_pay_price);
        this.radio_pay_choose = (RadioGroup) this.findViewById(R.id.radio_pay_choose);
    }

    @Override
    public void initData() {
        setTitle(R.string.title_pay);
    }

    @Override
    public void initListener() {
        this.findViewById(R.id.button_pay_go).setOnClickListener(this);
        radio_pay_choose.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                if (checkedId == R.id.radio_pay_weixin) {
                    pay_way = PayUtil.PAY_WX;
                } else if (checkedId == R.id.radio_pay_ali) {
                    pay_way = PayUtil.PAY_ALI;
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button_pay_go:
                if (pay_way == PAY_DEFALUT) {
                    toastShow("请选择支付方式");
                    return;
                }
                PayUtil.pay(this, pay_way, null, new IPayListener() {
                    @Override
                    public void payCallBack(int code, Object o) {
                        toastShow(o.toString());
                    }
                });
                break;
        }
    }
}
